Skip to content

True async api stable #19142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 177 commits into
base: master
Choose a base branch
from
Open

Conversation

EdmondDantes
Copy link

TrueAsync engine API

The TrueAsync engine API defines a pluggable interface that lets extensions register different async backends while the core supplies standardized primitives.

Key Components

  • Events: Low‑level representation of sockets, timers and other readiness sources
  • Coroutines: Stackful tasks
  • Scopes: Hierarchical lifetime management enabling grouped cancellation
  • Wakers: Event‑completion handlers that resume suspended coroutines

PR for https://wiki.php.net/rfc/true_async_engine_api

EdmondDantes and others added 30 commits May 24, 2025 13:49
Initial version of the asynchronous API for PHP. Includes only the API itself and the necessary core changes required for the API to function.
…ized into a method for retrieving any ClassEntry.

  Now, using this API function, you can obtain the required class entry by a type descriptor type.
Added API functions for coroutine context management:
- zend_async_context_set_t: set value by string or object key
- zend_async_context_get_t: get value by string or object key
- zend_async_context_has_t: check if key exists
- zend_async_context_delete_t: delete key-value pair

Includes convenience macros for easier usage:
ZEND_ASYNC_CONTEXT_SET_STR/OBJ, GET_STR/OBJ, HAS_STR/OBJ, DELETE_STR/OBJ
Added complete Context API implementation:
- Updated zend_async_scheduler_register signature to accept context functions
- Added context function pointers and registration in zend_async_API.c
- Context API supports both string and object keys
- Includes convenience macros for easy usage

This completes the core API infrastructure for coroutine context management.
- Remove separate context_set, context_get, context_has, context_delete functions
- Add single zend_async_new_context_fn function to create context instances
- Move context implementation to ext/async module using zend_async_context_t structure
- Update scheduler registration to include new_context_fn parameter
- Add context field to zend_async_globals_t and zend_coroutine_s
- Simplify Context API macros to ZEND_ASYNC_NEW_CONTEXT and ZEND_ASYNC_CURRENT_CONTEXT
% removal of the current Scope from the global structure
… always needs to be explicitly known. Macros like ZEND_ASYNC_CURRENT_SCOPE were updated.

  A new macro ZEND_ASYNC_MAIN_SCOPE was added for the main Scope.
…main coroutine can correctly return control.
* add macro START_REACTOR_OR_RETURN for reactor autostart
… is now passed to the main coroutine’s finalize method instead of being displayed on screen.

* Fixed an issue with correctly passing the exception into the coroutine.
… captures the exception, marking it as handled in another coroutine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants